package com.rc.saas.tenant.interceptor.parser;

import net.sf.jsqlparser.statement.select.Select;
import net.sf.jsqlparser.util.TablesNamesFinder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SelectParser {
    @Autowired
    private SubSelectParser subSelectParser;

    public String addWhere(Select select) throws Exception {
        TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();
        List<String> tableList = tablesNamesFinder.getTableList(select);
        if (tableList.size() == 0) {
            return select.toString();
        }

        subSelectParser.addCondition(select.getSelectBody());

        return select.toString();
    }

}
